package com.ineatconseil.yougo.components;

import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.BeginRender;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.ineatconseil.yougo.utils.DateUtils;

/**
 * Component use to format year and month to more convenient message.
 * 
 * @author johanblo
 * 
 */
public class YearAndMonthLabel {

	@Inject
	private Messages messages;

	@Parameter
	private int month = 0;

	@Parameter
	private int year = 0;

	@BeginRender
	void renderMessage(MarkupWriter writer) {

		if (year != 0 && month != 0) {
			writer.write(messages.get("monthlabel_" + month) + " " + year);
		} else {
			writer.write(messages.get("monthlabel_" + DateUtils.getCurrentMonth()) + " " + DateUtils.getCurrentYear());
		}
	}

}
